package com.buaa.aimall.Utils.Task;

import com.buaa.aimall.Utils.Service.CleanupService;
import com.buaa.aimall.Utils.Config.CleanupProperties;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CleanupTask {
    
    @Autowired
    private CleanupService cleanupService;
    
    @Autowired
    private CleanupProperties cleanupProperties;
    
    /**
     * 清理过期订单的任务
     * 需要在XXL-JOB管理界面配置定时任务，JobHandler名称为"cleanupOrdersJob"
     */
    @XxlJob("cleanupOrdersJob")
    public void cleanupOrders() {
        System.out.println("开始启动xxl");
        
        try {
            cleanupService.cleanupExpiredOrders();
        } catch (Exception e) {
            log.error("订单清理任务执行失败", e);
        }
    }
} 